home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / winterp-1.13 / src-server / wc_ScrollBar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-04  |  11.1 KB  |  290 lines

  1. /* -*-C-*-
  2. ********************************************************************************
  3. *
  4. * File:         wc_ScrollBar.c
  5. * RCS:          $Header: wc_ScrollBar.c,v 1.3 91/03/14 03:15:08 mayer Exp $
  6. * Description:  XM_SCROLL_BAR_WIDGET_CLASS
  7. * Author:       Niels Mayer, HPLabs
  8. * Created:      Sat Oct 28 04:35:49 1989
  9. * Modified:     Thu Oct  3 22:20:19 1991 (Niels Mayer) mayer@hplnpm
  10. * Language:     C
  11. * Package:      N/A
  12. * Status:       X11r5 contrib tape release
  13. *
  14. * WINTERP Copyright 1989, 1990, 1991 Hewlett-Packard Company (by Niels Mayer).
  15. * XLISP version 2.1, Copyright (c) 1989, by David Betz.
  16. *
  17. * Permission to use, copy, modify, distribute, and sell this software and its
  18. * documentation for any purpose is hereby granted without fee, provided that
  19. * the above copyright notice appear in all copies and that both that
  20. * copyright notice and this permission notice appear in supporting
  21. * documentation, and that the name of Hewlett-Packard and David Betz not be
  22. * used in advertising or publicity pertaining to distribution of the software
  23. * without specific, written prior permission.  Hewlett-Packard and David Betz
  24. * make no representations about the suitability of this software for any
  25. * purpose. It is provided "as is" without express or implied warranty.
  26. *
  27. * HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  28. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  29. * IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  30. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  31. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  32. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  33. * PERFORMANCE OF THIS SOFTWARE.
  34. *
  35. * See ./winterp/COPYRIGHT for information on contacting the authors.
  36. * Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  37. * Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  38. *
  39. ********************************************************************************
  40. */
  41. static char rcs_identity[] = "@(#)$Header: wc_ScrollBar.c,v 1.3 91/03/14 03:15:08 mayer Exp $";
  42.  
  43. #include <stdio.h>
  44. #include <Xm/Xm.h>
  45. #include <Xm/ScrollBar.h>
  46. #include "winterp.h"
  47. #include "user_prefs.h"
  48. #include "xlisp/xlisp.h"
  49. #include "w_funtab.h"
  50.  
  51.  
  52. extern Widget Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(); /* w_classes.c */
  53.  
  54.  
  55. /******************************************************************************
  56.  * typedef struct
  57.  * {
  58.  *    int reason;
  59.  *    XEvent * event;
  60.  *    int value;                 -- new slider location value
  61.  *    int pixel;                 -- this is a stupid name: contains the coord of the XmNto{Top,Bottom}Callback
  62.  * } XmScrollBarCallbackStruct;
  63.  ******************************************************************************/
  64. static LVAL s_CALLBACK_PIXEL;    /* initialized below in Wc_ScrollBar_Init() */
  65. static void Lexical_Bindings_For_XmScrollBarCallbackStruct(bindings_list, lexical_env, cd, o_widget)
  66.      LVAL bindings_list;    /* a list of symbols to which values from XmScrollBarCallbackStruct are bound */
  67.      LVAL lexical_env;        
  68.      XmScrollBarCallbackStruct* cd;
  69.      LVAL o_widget;        /* XLTYPE_WIDGETOBJ */
  70. {
  71.   extern LVAL s_CALLBACK_WIDGET, s_CALLBACK_REASON, s_CALLBACK_XEVENT, s_CALLBACK_VALUE; /* w_callbacks.c */
  72.   extern LVAL Wcb_Get_Callback_Reason_Symbol();    /* w_callbacks.c */
  73.   register LVAL s_bindname;
  74.  
  75.   for ( ; consp(bindings_list); bindings_list = cdr(bindings_list)) {
  76.  
  77.     s_bindname = car(bindings_list);
  78.  
  79.     if (s_bindname == s_CALLBACK_WIDGET) {
  80.       xlpbind(s_bindname, o_widget, lexical_env);
  81.     }
  82.     else if (s_bindname == s_CALLBACK_REASON) {
  83.       xlpbind(s_bindname, Wcb_Get_Callback_Reason_Symbol(cd->reason), lexical_env);
  84.     }
  85.     else if (s_bindname == s_CALLBACK_XEVENT) {
  86.       xlpbind(s_bindname, (cd->event) ? cv_xevent(cd->event) : NIL, lexical_env);
  87.     }
  88.     else if (s_bindname == s_CALLBACK_VALUE) {
  89.       xlpbind(s_bindname, cvfixnum((FIXTYPE) cd->value), lexical_env);
  90.     }
  91.     else if (s_bindname == s_CALLBACK_PIXEL) {
  92.       xlpbind(s_bindname, cvfixnum((FIXTYPE) cd->pixel), lexical_env);
  93.     }
  94.     else {
  95.       extern char temptext[];    /* from winterp.c */
  96.       sprintf(temptext,
  97.           "Unknown binding name in XmScrollBarCallbackStruct callback evaluator. Valid symbols are [%s %s %s %s %s].",
  98.           (char*) getstring(getpname(s_CALLBACK_WIDGET)),
  99.           (char*) getstring(getpname(s_CALLBACK_REASON)),
  100.           (char*) getstring(getpname(s_CALLBACK_XEVENT)),
  101.           (char*) getstring(getpname(s_CALLBACK_VALUE)),
  102.           (char*) getstring(getpname(s_CALLBACK_PIXEL)));
  103.       xlerror(temptext, s_bindname);
  104.     }
  105.   }
  106. }
  107.  
  108.  
  109. /******************************************************************************
  110.  * This is called indirectly via XtAddCallback() for callbacks returning
  111.  * an XmScrollBarCallbackStruct as call_data. 
  112.  ******************************************************************************/
  113. static void XmScrollBarCallbackStruct_Callbackproc(widget, client_data, call_data)
  114.      Widget    widget;
  115.      XtPointer client_data;
  116.      XtPointer call_data;
  117. {
  118.   extern void Wcb_Meta_Callbackproc(); /* w_callbacks.c */
  119.  
  120.   Wcb_Meta_Callbackproc(client_data, call_data,
  121.             Lexical_Bindings_For_XmScrollBarCallbackStruct,
  122.             NULL);
  123. }
  124.  
  125.  
  126. /******************************************************************************
  127.  * Same as WIDGET_CLASS's :add_callback method except that this understands
  128.  * how to get values from the XmScrollBarCallbackStruct.
  129.  * Specifying one or more of the following symbols in the callback bindings 
  130.  * list will bind that symbol's value in the lexical environment of the callback:
  131.  * CALLBACK_WIDGET
  132.  * CALLBACK_REASON
  133.  * CALLBACK_XEVENT
  134.  * CALLBACK_VALUE
  135.  * CALLBACK_PIXEL
  136.  ******************************************************************************/
  137. LVAL Xm_Scroll_Bar_Widget_Class_Method_ADD_CALLBACK()
  138. {
  139.   extern LVAL Wcb_Meta_Method_Add_Callback(); /* w_callbacks.c */
  140.  
  141.   return (Wcb_Meta_Method_Add_Callback(XmScrollBarCallbackStruct_Callbackproc, FALSE));
  142. }
  143.  
  144.  
  145. /******************************************************************************
  146.  * Same as WIDGET_CLASS's :set_callback method except that this understands
  147.  * how to get values from the XmScrollBarCallbackStruct.
  148.  * Specifying one or more of the following symbols in the callback bindings 
  149.  * list will bind that symbol's value in the lexical environment of the callback:
  150.  * CALLBACK_WIDGET
  151.  * CALLBACK_REASON
  152.  * CALLBACK_XEVENT
  153.  * CALLBACK_VALUE
  154.  * CALLBACK_PIXEL
  155.  ******************************************************************************/
  156. LVAL Xm_Scroll_Bar_Widget_Class_Method_SET_CALLBACK()
  157. {
  158.   extern LVAL Wcb_Meta_Method_Add_Callback(); /* w_callbacks.c */
  159.  
  160.   return (Wcb_Meta_Method_Add_Callback(XmScrollBarCallbackStruct_Callbackproc, TRUE));
  161. }
  162.  
  163.  
  164. /******************************************************************************
  165.  * (send <scrollbar_widget> :GET_VALUE) 
  166.  * ==> returns a list (<value> <slider_size> <increment> <page_increment>)
  167.  * all of which are FIXNUMs representing  the values of resources
  168.  * :XMN_VALUE, :XMN_SLIDER_SIZE, :XMN_INCREMENT, and :XMN_PAGE_INCREMENT
  169.  * respectively.
  170.  *
  171.  * Note that I couldn't call this method :GET_VALUES because it would override
  172.  * method :GET_VALUES on WIDGET_CLASS.
  173.  *
  174.  * void XmScrollBarGetValues (w, value, slider_size, increment, page_increment)
  175.  *    Widget w;
  176.  *    int *value;
  177.  *    int *slider_size;
  178.  *    int *increment;
  179.  *    int *page_increment;
  180.  ******************************************************************************/
  181. LVAL Xm_Scroll_Bar_Widget_Class_Method_GET_VALUE()
  182. {
  183.   LVAL self, result;
  184.   Widget widget_id;
  185.   int value, slider_size, increment, page_increment;
  186.   
  187.   widget_id = Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(&self);
  188.   xllastarg();
  189.  
  190.   XmScrollBarGetValues(widget_id, &value, &slider_size, &increment, &page_increment);
  191.  
  192.   xlsave1(result);        /* protect from gc */
  193.   result = cons(cvfixnum((FIXTYPE) page_increment), NIL);
  194.   result = cons(cvfixnum((FIXTYPE) increment), result);
  195.   result = cons(cvfixnum((FIXTYPE) slider_size), result);
  196.   result = cons(cvfixnum((FIXTYPE) value), result);
  197.   xlpop();
  198.   return (result);
  199. }
  200.  
  201.  
  202. /******************************************************************************
  203.  * (send <scrollbar_widget> :SET_VALUE <value> <slider_size> 
  204.  *                                     [[[<increment>] <page_increment>] <notify>])
  205.  * ==> returns <scrollbar_widget>.
  206.  * <value> is a fixnum specifying the slider position
  207.  *    (same as setting the resource :XMN_VALUE)
  208.  * <slider_size> is a fixnum specifying the size of the slider.
  209.  *    (same as setting resource :XMN_SLIDER_SIZE)
  210.  * <increment> is an optional fixnum specifying the amount of button increment
  211.  *    and decrement. (same as setting resource :XMN_INCREMENT).
  212.  * <page_increment> is an optional fixnum specifying the page increment size.
  213.  *    (same as setting resource :XMN_INCREMENT).
  214.  * <notify> is an optional Boolean, if NIL, the value changed callback will not
  215.  *     be activated, else it will.
  216.  * 
  217.  * Note that I couldn't call this method :SET_VALUES because it would override
  218.  * method :SET_VALUES on WIDGET_CLASS.
  219.  *
  220.  * void XmScrollBarSetValues (w, value, slider_size, 
  221.  *                            increment, page_increment, notify)
  222.  *        Widget w;
  223.  *        int value;
  224.  *        int slider_size;
  225.  *        int increment;
  226.  *        int page_increment;
  227.  *        Boolean notify;
  228.  ******************************************************************************/
  229. LVAL Xm_Scroll_Bar_Widget_Class_Method_SET_VALUE()
  230. {
  231.   LVAL self;
  232.   Widget widget_id;
  233.   int value, slider_size, increment, page_increment;
  234.   Boolean notify;
  235.  
  236.   widget_id = Wcls_Get_WIDGETOBJ_Argument_Returning_Validated_WidgetID(&self);
  237.   value = (int) getfixnum(xlgafixnum());
  238.   slider_size = (int) getfixnum(xlgafixnum());
  239.   if (moreargs()) {
  240.     increment = (int) getfixnum(xlgafixnum());
  241.     if (moreargs()) {
  242.       page_increment = (int) getfixnum(xlgafixnum());
  243.       if (moreargs())
  244.     notify = (xlgetarg() == NIL) ? FALSE : TRUE;
  245.       else
  246.     notify = FALSE;
  247.     }
  248.     else 
  249.       page_increment = notify = FALSE;
  250.   }
  251.   else 
  252.     increment = page_increment = notify = FALSE;
  253.   xllastarg();
  254.  
  255.   XmScrollBarSetValues(widget_id, value, slider_size,
  256.                increment, page_increment, notify);
  257.  
  258.   return (self);
  259. }
  260.  
  261.  
  262. /******************************************************************************
  263.  *
  264.  ******************************************************************************/
  265. Wc_ScrollBar_Init()
  266. {
  267.   LVAL o_XM_SCROLL_BAR_WIDGET_CLASS;
  268.   extern LVAL Wcls_Create_Subclass_Of_WIDGET_CLASS(); /* w_classes.c */
  269.   extern      xladdmsg();    /* from xlobj.c */
  270.  
  271.   o_XM_SCROLL_BAR_WIDGET_CLASS =
  272.     Wcls_Create_Subclass_Of_WIDGET_CLASS("XM_SCROLL_BAR_WIDGET_CLASS",
  273.                      xmScrollBarWidgetClass);
  274.  
  275.   xladdmsg(o_XM_SCROLL_BAR_WIDGET_CLASS, ":ADD_CALLBACK",
  276.            FTAB_Xm_Scroll_Bar_Widget_Class_Method_ADD_CALLBACK);
  277.  
  278.   xladdmsg(o_XM_SCROLL_BAR_WIDGET_CLASS, ":SET_CALLBACK",
  279.            FTAB_Xm_Scroll_Bar_Widget_Class_Method_SET_CALLBACK);
  280.  
  281.   xladdmsg(o_XM_SCROLL_BAR_WIDGET_CLASS, ":SET_VALUE",
  282.            FTAB_Xm_Scroll_Bar_Widget_Class_Method_SET_VALUE);
  283.  
  284.   xladdmsg(o_XM_SCROLL_BAR_WIDGET_CLASS, ":GET_VALUE",
  285.            FTAB_Xm_Scroll_Bar_Widget_Class_Method_GET_VALUE);
  286.  
  287.   s_CALLBACK_PIXEL = xlenter("CALLBACK_PIXEL");
  288. }
  289.